package me.zhengjie.modules.hanzi.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Data
@Component
@ConfigurationProperties(prefix = "ai.service")
public class AiServiceProperties {
    
    /**
     * 启用的AI服务提供商列表（按优先级排序）
     */
    private List<String> providers;
    
    /**
     * 各服务提供商的详细配置
     */
    private AiProviderConfig openai;
    private AiProviderConfig deepseek;
    private AiProviderConfig anthropic;
    private AiProviderConfig server;
    private AiProviderConfig local;
    
    /**
     * 全局配置
     */
    private GlobalConfig global;
    
    @Data
    public static class AiProviderConfig {
        private boolean enabled;
        private String apiKey;
        private String baseUrl;
        private String model;
        private String apiType;
        private Map<String, Object> apiPaths;
        private boolean useImageInput;
        private double temperature;
        private int maxTokens;
        private long timeout;
    }
    
    @Data
    public static class GlobalConfig {
        private int retryCount;
        private long retryDelayMs;
        private boolean fallbackToLocal;
    }
    
    /**
     * 根据提供商名称获取配置
     */
    public AiProviderConfig getProviderConfig(String providerName) {
        switch (providerName.toLowerCase()) {
            case "openai":
                return openai;
            case "deepseek":
                return deepseek;
            case "anthropic":
                return anthropic;
            case "server":
                return server;
            case "local":
                return local;
            default:
                throw new IllegalArgumentException("Unknown provider: " + providerName);
        }
    }
}